package com.example.football.controller;

import com.example.football.pojo.Peoplelikestar;
import com.example.football.pojo.Peopleliketeam;
import com.example.football.service.PeoplelikestarService;
import com.example.football.service.PeopleliketeamService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class PeoplelikestarController {
    @Resource
    private PeoplelikestarService cc;

    //全查
    @RequestMapping("peoplelikestarlist")
    public String queryAll(Model model) {
        List<Peoplelikestar> list = cc.queryAll();
        //存入model
        model.addAttribute("list", list);
        //控制跳转

        return "peoplelikestarlist";
    }

    @RequestMapping("removeByPeoplelikestarid")
    public String removeByPeoplelikestarid(Integer id) {
        try {
            cc.removeByPeoplelikestarid(id);
            return "redirect:/peoplelikestarlist";
        } catch (Exception e) {
            return "error";
        }
    }

    @PostMapping("findByLikestar")
    public String findByLikestar(String likestar, Model model){
        List<Peoplelikestar> list = cc.queryByLikestar(likestar);
        //存入model
        model.addAttribute("list", list);
        return "peoplelikestarlist";
    }



    @RequestMapping("addPeoplelikestarPage")
    public String addPeoplelikestarPage() {
        return "addpeoplelikestar";
    }

    @RequestMapping("addPeoplelikestar")
    public String addPeoplelikestar(Peoplelikestar peoplelikestar) {
        try {
            cc.addPeoplelikestar(peoplelikestar);
            return "redirect:/peoplelikestarlist";
        } catch (Exception e) {
            e.printStackTrace();
            return "error";
        }
    }



    @GetMapping("findById4")
    public String findById(Integer id, Model model){
        Peoplelikestar list = cc.queryById(id);
        //存入model
        model.addAttribute("list", list);
        return "updatepeoplelikestar";
    }

    //数据修改
    @PostMapping("updatePeoplelikestar")
    public String changePeoplelikestar(Peoplelikestar peoplelikestar) {
        try {
            cc.changePeoplelikestar(peoplelikestar);
            return "redirect:/peoplelikestarlist";
        } catch (Exception e) {
            return "error";
        }
    }
}
